const http = require("http");
const path = require("path")
const fs = require("fs");
http.createServer((req, res) => {
    switch (req.method) {
        case "GET":
            getData(req, res);
            break;
        case "POST":
            postData(req, res);
            break;
        case "PUT":
            putData(req, res);
            break;
        case "DELETE":
            deleteData(req, res);
            break;
    }
}).listen(8080);

function getData(req, res) {
    console.log(req.method)
    let filePath = path.join(__dirname, "testMethod.html");
    let fileContent = fs.readFileSync(filePath);
    res.end(fileContent + " the client mehod is  " + req.method);
}

function postData(req, res) {
    console.log(req.method)
    res.end("the client mehod is" + req.method)
}

function putData(req, res) {
    console.log(req.method)
    res.end("the client mehod is" + req.method)
}

function deleteData(req, res) {
    console.log(req.method)
    res.end("the client mehod is" + req.method)
}
console.log("server is listening 8080");